package com.corner.system.service.impl;

import com.corner.common.exception.GlobalException;
import com.corner.system.domain.Approval;
import com.corner.system.mapper.ApprovalMapper;
import com.corner.system.service.ApprovalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @program: corner-admin
 * @description: 审批统计表服务类
 * @author: lydms
 * @create: 2023-11-20 14:00
 **/
@Service
public class ApprovalServiceImpl implements ApprovalService {

    @Autowired
    private ApprovalMapper approvalMapper;

    @Override
    public void updateApprovalById(Approval approval) throws Exception {
        if(approval.getApprovalId() == null){
            throw new GlobalException("审批编号为空！");
        }
        Approval up = new Approval();
        up.setApprovalId(approval.getApprovalId());
        //暂时只允许更新此字段
        if(approval.getExportTime()!=null){
            up.setExportTime(approval.getExportTime());
        }
        if(approval.getRefuseReason()!=null){
            up.setRefuseReason(approval.getRefuseReason());
        }
        int i = approvalMapper.updateApproval(up);

        if(i<=0){
            throw new GlobalException("更新失败！");
        }
    }

    @Override
    public List<Map> getApprovalList(Approval approval) {
        List<Map> approvals = approvalMapper.approvalInfoList(approval);
        return approvals;
    }
}
